package com.sicheng.lc.杂题.滑动窗口专题;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/12 20:43
 */
public class 重复的DNA序列 {
    //https://leetcode.cn/problems/repeated-dna-sequences/

    static int n = 10;
    static HashSet<String> map = new HashSet<>(20000);
    static HashSet<String> set = new HashSet<>(10000);

    {
        set.clear();
        map.clear();
    }

    public List<String> findRepeatedDnaSequences(String s) {
        int l = 0;

        for (int r = 0; r < s.length(); r++) {
            if (r - l + 1 == n) {
                String cur = s.substring(l, r + 1);
                if (map.contains(cur)) {
                    set.add(cur);
                } else {
                    map.add(cur);
                }
                l++;
            }
        }
        return new ArrayList<>(set);
    }
}
